package yaml

import (
	"gopkg.in/yaml.v3"
)

const (
	Name      = "yaml"
	ShortName = "yml"
)

var DefaultCodec = &codec{}

type codec struct{}

// Name 编解码器名称
func (codec) Name() string {
	return Name
}

// Marshal 编码
func (codec) Marshal(v any) ([]byte, error) {
	return yaml.Marshal(v)
}

// Unmarshal 解码
func (codec) Unmarshal(data []byte, v any) error {
	return yaml.Unmarshal(data, v)
}

// Marshal 编码
func Marshal(v any) ([]byte, error) {
	return DefaultCodec.Marshal(v)
}

// Unmarshal 解码
func Unmarshal(data []byte, v any) error {
	return DefaultCodec.Unmarshal(data, v)
}
